<?php
namespace app\admin\controller;

class Category extends Base{
	function _initialize(){
		parent::_initialize();
		$up_parent_id = $this->_get('up_parent_id');
		if($this->_parent_id){
			$this->_parent_name = model('Category')->where(array('category_id' => $this->_parent_id))->value('title');
			$this->assign('_parent_name', $this->_parent_name);
		}
		// 设置跳转地址
		$this->_jump_url = url('index', array('module' => $this->_module, 'parent_id' => $this->_parent_id, 'up_parent_id' => $up_parent_id));
	}
	public function index(){
		if($this->_parent_name){
			$this->add_step($this->_parent_name);
		}
		$where['parent_id'] = $this->_parent_id;
		return parent::index('', $where);
	}

	// 删除
	public function delete(){
		$category_id = $this->_get('category_id', '对不起，ID不能为空！');

		if(model('Category')->where(array('parent_id' => $category_id))->count()){
			$this->error('对不起，还有下级内容，无法删除！');
		}else{
			model('Category')->where(array('category_id' => $category_id))->delete();
			$this->success('删除成功！');
		}
	}
	
}